package util

import "math"

type Page struct {
	TotalCount  int `json:"total_count"`  // 总记录数
	TotalPages  int `json:"total_pages"`  // 总页数
	CurrentPage int `json:"current_page"` // 当前页数
	PageSize    int `json:"page_size"`    // 每页记录数
	//Data        []interface{} `json:"data"`         // 当前页的数据
}

// NewPagination 创建分页实例
func NewPagination(totalCount, currentPage, pageSize int) *Page {
	totalPages := int64(math.Ceil(float64(totalCount) / float64(pageSize)))
	if currentPage < 1 {
		currentPage = 1
	} else if currentPage > int(totalPages) {
		currentPage = int(totalPages)
	}
	return &Page{
		TotalCount:  totalCount,
		TotalPages:  int(totalPages),
		CurrentPage: currentPage,
		PageSize:    pageSize,
	}
}
